<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>物资归还记录</title>
    <jsp:include page="/WEB-INF/view/commons/css.jsp" />
    <style type="text/css">
    	.input-item {
    		border: 0px !import;
    		outline:none;
    		cursor: pointer;
    	}
    </style>
</head>
<body >
<div id="main-container" class="container-fluid">
    <form  action="appMaterialsReturn/saveAll" name="inputForm" id="inputForm" method="post" class="form-horizontal">
    <input name="lendId" value="${appMaterialsLend.id}" type="hidden" />
    <input name="returnCode" value="${barCode}" type="hidden" />
    <input name="grantOrgName" value="${appMaterialsLend.grantOrgName}" type="hidden" />
    <input name="grantOrgId" value="${appMaterialsLend.grantOrgId}" type="hidden" />
    <input name="orgId" value="${appMaterialsLend.orgId}" type="hidden" />
    <input name="orgName" value="${appMaterialsLend.orgName}" type="hidden" />
        <div class="mt20">
                <%--<div class="form-group row">--%>
                    <%--<div class="col-sm-5">--%>
                        <%--<input class="form-control inline" type="text" name="returnTitle" value="">--%>
                    <%--</div>--%>
                <%--</div>--%>
            <div class="info-title">
                <h2>物资归还登记表</h2>
                <img src="data:image/png;base64,${barCodeImg}">
            </div>
            <div class="row mt20">
                <div class="col-sm-4" style="padding-top: 7px">NO.${barCode}</div>
                <div class="col-sm-4" style="padding-top: 7px; text-align: center;">借出经办人:${appMaterialsLend.agentName}</div>
                <div class="form-group col-sm-4" style="padding-right: 0">
                    <label class="control-label col-sm-4">来往单位: </label>
                    <label class="control-label">${appMaterialsLend.orgName}</label>
                </div>
            </div>
            <table id="table_data" class="table table-striped table-bordered table-hover">
                <thead>
                <tr>
                    <th style="width: 30px;">序号</th>
                    <th style="width: 150px;">物资名称</th>
                    <th style="width: 50px;">规格</th>
                    <th style="width: 50px;">单位</th>
                    <th style="width: 50px;">出借数量</th>
                    <th style="width: 150px;">待归还数量</th>
                    <th style="width: 150px;">本次归还数量</th>
                    <th style="width: 150px;">备注</th>
                </tr>
                </thead>
                <tbody id="maintbody">
                <c:forEach var="each" varStatus="vs" items="${appLendDetailList}">
                     <tr>
                         <td class='center'>${vs.index+1}</td>
                         <td class='center'>
                             <span id="materialsName${vs.index}s">${each.materialsName}</span>
                             <input type="hidden" id="materialsId${vs.index}" name="itemEntity[${vs.index}].materialsId" value="${each.materialsId}"/>
                             <input type="hidden" id="materialsName${vs.index}" name="itemEntity[${vs.index}].materialsName" value="${each.materialsName}"/>
                         </td>
                         <td class='center'>
                             <span id="specification${vs.index}s">${each.specification}</span>
                             <input type="hidden"  id="specification${vs.index}" name="itemEntity[${vs.index}].specification" value="${each.specification}"/>
                         </td>
                         <td class='center'>
                             <span id="unit${vs.index}s">${each.unit}</span>
                             <input type="hidden"  id="unit${vs.index}" name="itemEntity[${vs.index}].unit" value="${each.unit}"/>
                         </td>
                         <td class='center'>
               				 <span id="lendNum${vs.index}s">${each.lendNum}</span>
                             <input type="hidden" id="lendNum${vs.index}" name="itemEntity[${vs.index}].lendNum" value="${each.lendNum}" placeholder="" min='1'/>
                         </td>
                         <td class='center'>
                         	<span id="unit${vs.index}s">${each.needReturnNum}</span>
                            <input type="hidden" id="needReturnNum${vs.index}" name="itemEntity[${vs.index}].needReturnNum" value="${each.needReturnNum}" class="input-item" placeholder="" readonly/>
                        </td>
                         <td class='center'>
                             <input type="number" id="returnNum${vs.index}" name="itemEntity[${vs.index}].returnNum" value="0" placeholder="" min="0" max="${each.needReturnNum}" required=true/>
                         </td>
                         <td class='center'>
                             <input type="text" id="remark${vs.index}" name="itemEntity[${vs.index}].remark" value="" placeholder="" data-rule-maxlength="50"/>
                         </td>
                     </tr>
                 </c:forEach>
                </tbody>
            </table>
            <div class="row">
                <div class="col-sm-4">发放单位：${appMaterialsLend.grantOrgName} ${user.name} </div>
                <div class="col-sm-4">归还时间：</div>
                <div class="col-sm-4 form-group">
                    <div class="control-label col-sm-4">经办人：</div>
                    <div class="col-sm-8">
                        <input type="text" name="agentName" class="form-control">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-8 form-group">
                    <div class="col-sm-2" style="width: 10%">备注：</div>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" name="remark" >
                    </div>
                </div>
            </div>
        </div>
    <div class="form-group">
        <div class="center">
        	<button type="button" class="btn btn-sm btn-primary" onclick="handlerSaveAll();"><i class="fa fa-floppy-o"></i> 签署</button>
        </div>
    </div>
    </form>
</div><!--/#main-container-->

<!-- script start -->
<jsp:include page="/WEB-INF/view/commons/js.jsp" />
<script type="text/javascript">
    $(document).ready(function(e) {
        var options = {
            rules:{
                returnTitle : { required : true, maxlength : 100, isText: true },
                orgName : { required : true, maxlength : 100 },
                orgId : { required : true, digits : true  },
                grantOrgName : { required : true, maxlength : 20 },
                agentName : { required : true, maxlength : 50, isText: true }
            }
        };
        $("#inputForm").validate(options);
        
        $("#orgSelect").change(function(e){
        	if ($(this).val() == "") {
        		$(".fa-org").removeClass("fa-check");
        	}else{
        		$(".fa-org").addClass("fa-check");
        	}
        });
        $("input[name=agentName]").bind('input propertychange', function(){
        	if ($(this).val() == "") {
        		$(".fa-agentName").removeClass("fa-check");
        	}else{
        		$(".fa-agentName").addClass("fa-check");
        	}
        });
    });
    
    function handlerSaveAll(){
    	 var trList = $("#maintbody").children("tr");
    	 var flag = false;
         for (var i=0;i<trList.length;i++) {
             var tdArr = trList.eq(i).find("td");
             var returnNum = tdArr.eq(6).find('input').val();
             if(returnNum != 0){
            	 flag = true;
            	 break;
             }
         }
         if(!flag){ // 如果所有记录都没有填写归还数量，则提示
        	 layer.alert("请填写本次归还数量");
         }else{
        	if($("#inputForm").valid()){
	   			$("#inputForm").ajaxSubmit({
	   				type:'post',
	                 dataType:'json',
	                 success:function(data){
	                     if(data.success){
	                         $('#searchBtn', parent.document).click();
	                   	 		layer.open({
	                                 title: "待签署",
	                                 type: 2,
	                                 content: "appMaterialsReturn/returnSign/"+data.data,
	                                 area: ['60%', '90%'],
	                                 success:function(layero,index){
	                                 	
	                                 }
	                             });
	                             //closeIframe();
	                     }else{
	                         layer.alert(data.msg);
	                     }
	                 }
	   			});
	   		}
         }
    }
    
</script>
<!-- script end -->
</body>
</html>
